﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import org.aswing.geom.*;

    public class BorderLayout extends EmptyLayout {

        public static const NORTH:String = "North";
        public static const SOUTH:String = "South";
        public static const EAST:String = "East";
        public static const WEST:String = "West";
        public static const CENTER:String = "Center";
        public static const BEFORE_FIRST_LINE:String = "First";
        public static const AFTER_LAST_LINE:String = "Last";
        public static const BEFORE_LINE_BEGINS:String = "Before";
        public static const AFTER_LINE_ENDS:String = "After";
        public static const PAGE_START:String = "First";
        public static const PAGE_END:String = "Last";
        public static const LINE_START:String = "Before";
        public static const LINE_END:String = "After";

        private var hgap:Number;
        private var vgap:Number;
        private var north:Component;
        private var west:Component;
        private var east:Component;
        private var south:Component;
        private var center:Component;
        private var firstLine:Component;
        private var lastLine:Component;
        private var firstItem:Component;
        private var lastItem:Component;
        private var defaultConstraints:String;

        public function BorderLayout(_arg1:int=0, _arg2:int=0){
            this.hgap = _arg1;
            this.vgap = _arg2;
            this.defaultConstraints = CENTER;
        }
        public function setDefaultConstraints(_arg1:Object):void{
            this.defaultConstraints = _arg1.toString();
        }
        public function getHgap():int{
            return (this.hgap);
        }
        public function setHgap(_arg1:int):void{
            this.hgap = _arg1;
        }
        public function getVgap():int{
            return (this.vgap);
        }
        public function setVgap(_arg1:int):void{
            this.vgap = _arg1;
        }
        override public function addLayoutComponent(_arg1:Component, _arg2:Object):void{
            var _local3:String = ((_arg2)!=null) ? _arg2.toString() : null;
            this.addLayoutComponentByAlign(_local3, _arg1);
        }
        private function addLayoutComponentByAlign(_arg1:String, _arg2:Component):void{
            if (_arg1 == null){
                _arg1 = this.defaultConstraints;
            };
            if (CENTER == _arg1){
                this.center = _arg2;
            } else {
                if (NORTH == _arg1){
                    this.north = _arg2;
                } else {
                    if (SOUTH == _arg1){
                        this.south = _arg2;
                    } else {
                        if (EAST == _arg1){
                            this.east = _arg2;
                        } else {
                            if (WEST == _arg1){
                                this.west = _arg2;
                            } else {
                                if (BEFORE_FIRST_LINE == _arg1){
                                    this.firstLine = _arg2;
                                } else {
                                    if (AFTER_LAST_LINE == _arg1){
                                        this.lastLine = _arg2;
                                    } else {
                                        if (BEFORE_LINE_BEGINS == _arg1){
                                            this.firstItem = _arg2;
                                        } else {
                                            if (AFTER_LINE_ENDS == _arg1){
                                                this.lastItem = _arg2;
                                            } else {
                                                this.center = _arg2;
                                            };
                                        };
                                    };
                                };
                            };
                        };
                    };
                };
            };
        }
        override public function removeLayoutComponent(_arg1:Component):void{
            if (_arg1 == this.center){
                this.center = null;
            } else {
                if (_arg1 == this.north){
                    this.north = null;
                } else {
                    if (_arg1 == this.south){
                        this.south = null;
                    } else {
                        if (_arg1 == this.east){
                            this.east = null;
                        } else {
                            if (_arg1 == this.west){
                                this.west = null;
                            };
                        };
                    };
                };
            };
            if (_arg1 == this.firstLine){
                this.firstLine = null;
            } else {
                if (_arg1 == this.lastLine){
                    this.lastLine = null;
                } else {
                    if (_arg1 == this.firstItem){
                        this.firstItem = null;
                    } else {
                        if (_arg1 == this.lastItem){
                            this.lastItem = null;
                        };
                    };
                };
            };
        }
        override public function minimumLayoutSize(_arg1:Container):IntDimension{
            return (_arg1.getInsets().getOutsideSize());
        }
        override public function preferredLayoutSize(_arg1:Container):IntDimension{
            var _local5:IntDimension;
            var _local2:IntDimension = new IntDimension(0, 0);
            var _local3:Boolean;
            var _local4:Component;
            _local4 = this.getChild(EAST, _local3);
            if (_local4 != null){
                _local5 = _local4.getPreferredSize();
                _local2.width = (_local2.width + (_local5.width + this.hgap));
                _local2.height = Math.max(_local5.height, _local2.height);
            };
            _local4 = this.getChild(WEST, _local3);
            if (_local4 != null){
                _local5 = _local4.getPreferredSize();
                _local2.width = (_local2.width + (_local5.width + this.hgap));
                _local2.height = Math.max(_local5.height, _local2.height);
            };
            _local4 = this.getChild(CENTER, _local3);
            if (_local4 != null){
                _local5 = _local4.getPreferredSize();
                _local2.width = (_local2.width + _local5.width);
                _local2.height = Math.max(_local5.height, _local2.height);
            };
            _local4 = this.getChild(NORTH, _local3);
            if (_local4 != null){
                _local5 = _local4.getPreferredSize();
                _local2.width = Math.max(_local5.width, _local2.width);
                _local2.height = (_local2.height + (_local5.height + this.vgap));
            };
            _local4 = this.getChild(SOUTH, _local3);
            if (_local4 != null){
                _local5 = _local4.getPreferredSize();
                _local2.width = Math.max(_local5.width, _local2.width);
                _local2.height = (_local2.height + (_local5.height + this.vgap));
            };
            var _local6:Insets = _arg1.getInsets();
            _local2.width = (_local2.width + (_local6.left + _local6.right));
            _local2.height = (_local2.height + (_local6.top + _local6.bottom));
            return (_local2);
        }
        override public function getLayoutAlignmentX(_arg1:Container):Number{
            return (0.5);
        }
        override public function getLayoutAlignmentY(_arg1:Container):Number{
            return (0.5);
        }
        override public function layoutContainer(_arg1:Container):void{
            var _local10:IntDimension;
            var _local2:IntDimension = _arg1.getSize();
            var _local3:Insets = _arg1.getInsets();
            var _local4:int = _local3.top;
            var _local5:int = (_local2.height - _local3.bottom);
            var _local6:int = _local3.left;
            var _local7:int = (_local2.width - _local3.right);
            var _local8:Boolean;
            var _local9:Component;
            _local9 = this.getChild(NORTH, _local8);
            if (_local9 != null){
                _local10 = _local9.getPreferredSize();
                _local9.setBounds(new IntRectangle(_local6, _local4, (_local7 - _local6), _local10.height));
                _local4 = (_local4 + (_local10.height + this.vgap));
            };
            _local9 = this.getChild(SOUTH, _local8);
            if (_local9 != null){
                _local10 = _local9.getPreferredSize();
                _local9.setBounds(new IntRectangle(_local6, (_local5 - _local10.height), (_local7 - _local6), _local10.height));
                _local5 = (_local5 - (_local10.height + this.vgap));
            };
            _local9 = this.getChild(EAST, _local8);
            if (_local9 != null){
                _local10 = _local9.getPreferredSize();
                _local9.setBounds(new IntRectangle((_local7 - _local10.width), _local4, _local10.width, (_local5 - _local4)));
                _local7 = (_local7 - (_local10.width + this.hgap));
            };
            _local9 = this.getChild(WEST, _local8);
            if (_local9 != null){
                _local10 = _local9.getPreferredSize();
                _local9.setBounds(new IntRectangle(_local6, _local4, _local10.width, (_local5 - _local4)));
                _local6 = (_local6 + (_local10.width + this.hgap));
            };
            _local9 = this.getChild(CENTER, _local8);
            if (_local9 != null){
                _local9.setBounds(new IntRectangle(_local6, _local4, (_local7 - _local6), (_local5 - _local4)));
            };
        }
        private function getChild(_arg1:String, _arg2:Boolean):Component{
            var _local3:Component;
            if (_arg1 == NORTH){
                _local3 = ((this.firstLine)!=null) ? this.firstLine : this.north;
            } else {
                if (_arg1 == SOUTH){
                    _local3 = ((this.lastLine)!=null) ? this.lastLine : this.south;
                } else {
                    if (_arg1 == WEST){
                        _local3 = (_arg2) ? this.firstItem : this.lastItem;
                        if (_local3 == null){
                            _local3 = this.west;
                        };
                    } else {
                        if (_arg1 == EAST){
                            _local3 = (_arg2) ? this.lastItem : this.firstItem;
                            if (_local3 == null){
                                _local3 = this.east;
                            };
                        } else {
                            if (_arg1 == CENTER){
                                _local3 = this.center;
                            };
                        };
                    };
                };
            };
            if (((!((_local3 == null))) && (!(_local3.isVisible())))){
                _local3 = null;
            };
            return (_local3);
        }
        public function toString():String{
            return ((((("BorderLayout[hgap=" + this.hgap) + ",vgap=") + this.vgap) + "]"));
        }

    }
}//package org.aswing 
